%% ---------------------- Phase shift ------------------------- %%
%   Created Date    : 05 Mar 2013
%   Modified Date   : 05 Apr 2013
%   Version         : 2.0  
%   Author Name     : Sungjin Kim
% ---------------------------------------------------------------------- %%

%% BEGIN OF FUNCTION %%
function [complex_freDomain, complex_PC_FidData]= phaseShift(data, zero_order, first_order, center_offset, dataPoint_shift, dataPoint_shift_direction)
    
    bandwidth=4006;
    len_data = whos('data');
    len_data = len_data.size(1);

    magnitude_data = abs(data);                 % magnitude 
    phase_angle=angle(data);                    % phase angle
    first_order_shift_array=zeros(1,len_data);

    % first-order phase angle %
    for idx_fre = 1 : len_data
        % first order offset from -bandwidth/2 to bandwidth/2
        first_order_shift_array(idx_fre) = 2*first_order * ((idx_fre - len_data/2 -1)*bandwidth/len_data - center_offset)/bandwidth;
    end

    phase_angle=phase_angle + zero_order + first_order_shift_array';                    % shifted phase angle
    real_data=magnitude_data .* cos(phase_angle);                                       % phase shift
    imag_data=magnitude_data .* sin(phase_angle);                                       % phase shift
    complex_freDomain = complex(real_data, imag_data);                                  % make complex number

    % shift the data whether right or left %
    if dataPoint_shift_direction==1
        complex_freDomain = datashift(complex_freDomain, dataPoint_shift, 0);   % for left, input 0, or for right, input 1.
    elseif dataPoint_shift_direction==0
        complex_freDomain = datashift(complex_freDomain, dataPoint_shift, 1);   % for left, input 0, or for right, input 1.
    else
        message('Data shift direction error');
        return;
    end

    complex_PC_FidData = ifft(complex_freDomain);                                                      % Inverse FFT for making shifted FID dada. 
    complex_freDomain = datashift(complex_freDomain, dataPoint_shift, dataPoint_shift_direction);     % for left, input 0, or for right, input 1.
    
    return;
   
end % END OF FUNCTION %